﻿using System;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;

namespace TourGuideApp
{
    public partial class StopsListPage : PhoneApplicationPage
    {
        public StopsListPage()
        {
            InitializeComponent();
        }

        // When page is navigated to set data context to selected item in list
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var tours = (Expression.Blend.SampleData.TourSampleDataSource.toursList)App.Current.Resources["TourSampleDataSource"];
            DataContext = tours.tourCollection[App.tourIndex];
        }

        private void listBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            //Do nothing if there is no selection
            if (stopsListBox.SelectedIndex == -1)
                return;
            App.stopIndex = stopsListBox.SelectedIndex;
            //Navigate to details page and inform the selection
            NavigationService.Navigate(new Uri("/StopDetailsPage.xaml", UriKind.Relative));
            //Reset to no selection
            stopsListBox.SelectedIndex = -1;
        }

        private void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            //MessageBox.Show("Tour: "+App.tourIndex);
        }
    }
}